//  this library.
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:hktk_app/util/font_util.dart';
import 'package:hktk_app/util/view_util.dart';
import 'package:hktk_app/widget/mine/image_upload_widget.dart';

/// 反馈描述组件
class FeedbackWidget extends StatefulWidget {
  /// 反馈描述控制器
  final TextEditingController textEditingController;

  const FeedbackWidget({super.key, required this.textEditingController});

  @override
  State<FeedbackWidget> createState() => _FeedbackWidgetState();
}

class _FeedbackWidgetState extends State<FeedbackWidget> {
  /// 输入字数
  late int _textNum;

  @override
  void initState() {
    super.initState();
    _textNum = 0;
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 615,
      padding: EdgeInsets.fromLTRB(24, 30, 23, 23),
      decoration: BoxDecoration(
        color: colorWhite1,
        borderRadius: BorderRadius.circular(16),
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          _titleItem(),
          hiSpace(height: 11),
          Expanded(child: _textItem()),
          hiSpace(height: 15),
          _bottomItem(),
        ],
      ),
    );
  }

  /// 标题组件
  _titleItem() {
    return Text(
      "反馈描述",
      style: FontUtil.fontBlack1(26, fontWeight: FontWeight.w500),
    );
  }

  /// 输入框
  _textItem() {
    return SizedBox(
      height: 273,
      child: TextField(
        controller: widget.textEditingController,
        // 设置光标颜色
        cursorColor: colorBlue1,
        // 光标高度
        cursorHeight: 42,
        // 样式
        style: FontUtil.fontGrey5(30),
        // 最多行数
        maxLines: 7,
        // 装饰
        decoration: InputDecoration(
          // 去掉textField自定的高度
          isCollapsed: true,
          // 内容边距
          contentPadding: EdgeInsets.only(bottom: 3),
          // 去除边框
          border: InputBorder.none,
          // 提示语句
          hintText: "说说您的建议或问题，以便我们提供更好的服务（5 个字以上）",
          // 提示语句样式
          hintStyle: FontUtil.fontGrey5(20),
        ),
        // 限制输入长度
        inputFormatters: [
          LengthLimitingTextInputFormatter(300),
        ],
        // 内容变化方法
        onChanged: (text) {
          setState(() {
            _textNum = text.length;
          });
        },
      ),
    );
  }

  /// 底部组件
  _bottomItem() {
    return Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      crossAxisAlignment: CrossAxisAlignment.end,
      children: [
        _bottomLeft(),
        _bottomRight(),
      ],
    );
  }

  /// 底部左边显示
  _bottomLeft() {
    return Padding(
      padding: EdgeInsets.only(bottom: 2),
      child: const ImageUploadWidget(),
    );
  }

  /// 右边组件
  _bottomRight() {
    return Text(
      "$_textNum/300",
      style: FontUtil.fontGrey1(24),
    );
  }
}
